package com.ruoyi.items.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.items.domain.TbOrderItems;
import com.ruoyi.items.service.ITbOrderItemsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单项表Controller
 * 
 * @author txt
 * @date 2025-02-05
 */
@RestController
@RequestMapping("/items/items")
public class TbOrderItemsController extends BaseController
{
    @Autowired
    private ITbOrderItemsService tbOrderItemsService;

    /**
     * 查询订单项表列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TbOrderItems tbOrderItems)
    {
        startPage();
        List<TbOrderItems> list = tbOrderItemsService.selectTbOrderItemsList(tbOrderItems);
        return getDataTable(list);
    }

    /**
     * 导出订单项表列表
     */
    @Log(title = "订单项表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbOrderItems tbOrderItems)
    {
        List<TbOrderItems> list = tbOrderItemsService.selectTbOrderItemsList(tbOrderItems);
        ExcelUtil<TbOrderItems> util = new ExcelUtil<TbOrderItems>(TbOrderItems.class);
        util.exportExcel(response, list, "订单项表数据");
    }

    /**
     * 获取订单项表详细信息
     */
    @GetMapping(value = "/{orderItemId}")
    public AjaxResult getInfo(@PathVariable("orderItemId") Long orderItemId)
    {
        return success(tbOrderItemsService.selectTbOrderItemsByOrderItemId(orderItemId));
    }

    @GetMapping(value = "/order/{orderId}")
    public AjaxResult getDetailInfo(@PathVariable("orderId") Long orderId)
    {
        return success(tbOrderItemsService.getDetailInfo(orderId));
    }

    /**
     * 新增订单项表
     */
    @Log(title = "订单项表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbOrderItems tbOrderItems)
    {
        return toAjax(tbOrderItemsService.insertTbOrderItems(tbOrderItems));
    }

    /**
     * 修改订单项表
     */
    @Log(title = "订单项表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbOrderItems tbOrderItems)
    {
        return toAjax(tbOrderItemsService.updateTbOrderItems(tbOrderItems));
    }

    /**
     * 删除订单项表
     */
    @Log(title = "订单项表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderItemIds}")
    public AjaxResult remove(@PathVariable Long[] orderItemIds)
    {
        return toAjax(tbOrderItemsService.deleteTbOrderItemsByOrderItemIds(orderItemIds));
    }
}
